package com.aranandroid.customview.ui

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.aranandroid.customview.R
import com.aranandroid.customview.ui.square.*
import com.blankj.utilcode.util.SPUtils
import kotlinx.android.synthetic.main.activity_fragment.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class FragmentActivity : AppCompatActivity() {
    @SuppressLint("WrongViewCast")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_fragment)
        var farga = AFragment();
        var fargb = CFragment();
        var fargc = DFragment();
        var fargd = BFragment();
        var farge = BFragment();
        var fargf = BFragment();
        var fargh = BFragment();
        var fargi = BFragment();
        var fargj = BFragment();
        fragment_bottom.fragments = linkedMapOf(
            Pair(R.id.a, farga),
            Pair(R.id.b, fargb),
            Pair(R.id.c, fargc),
            Pair(R.id.d, fargd),
            Pair(R.id.e, farge),
            Pair(R.id.f, fargf),
            Pair(R.id.h, fargh),
            Pair(R.id.i, fargi),
            Pair(R.id.j, fargj),
        )


        fragment_bottom.changeItme = { _, checkedId ->
            Log.e("TAG", "onCreate: " + checkedId)
        }





        GlobalScope.launch {
           delay(200)
            fargd.viewModel.comData.postValue("d")
            farge.viewModel.comData.postValue("e")
            fargf.viewModel.comData.postValue("f")
            fargh.viewModel.comData.postValue("h")
            fargi.viewModel.comData.postValue("i")
            fargj.viewModel.comData.postValue("j")
            var iii = SPUtils.getInstance().getInt("iii",1)
            delay(10000)
            fragment_bottom.fragments?.forEach{ t, u ->
                if(u is BFragment)
                u.viewModel.comData.postValue(iii++.toString())
            }
            delay(10000)
            fragment_bottom.fragments?.forEach{ t, u ->
                if(u is BFragment)
                Log.e("BFragment", u.viewModel.comData.value )
            }
            SPUtils.getInstance().put("iii",iii)

        }

    }


}